<%@ page language="java" contentType="text/html; charset=UTF-8"	 pageEncoding="UTF-8"%>
<%@ include file="../include/laypublic.jsp"%>
<!DOCTYPE html>
<html>
<head>
</head>
  <title>收款单登记表管理</title>
  <style type="text/css">
  	.layui-form-select dl{
		max-height: 150px; // 原值为300，调节高度建议为50的倍数
	}
	.layui-form-label{width: 130px;}
  </style>
</head>
<body>
  <div class="layui-fluid">   
    <div class="layui-card">
      <!-- 查询区域  -->
      <div id="query-form" class="layui-form layui-card-header layuiadmin-card-header-auto">
        <div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">项目ID：</label>
				<div class="layui-input-inline">
					<input type="text" name="proCode" placeholder="请输入" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label">项目名称：</label>
				<div class="layui-input-inline">
					<input type="text" name="proName" placeholder="请输入" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label">收款类型：</label>
				<div class="layui-input-inline">
					<select name="incomeType">
						<c:if test="${not empty incomeBillType }">
							<c:forEach items="${incomeBillType}" var="type">
								<option value="${type.code}">${type.name }</option>
							</c:forEach>
						</c:if>
					</select>
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label">创建日期：</label>
				<div class="layui-input-inline">
					<input type="text" class="layui-input" id="sent-laydate-start" name="startDate" readonly placeholder="开始日期">
				</div>
				<div class="layui-form-mid">
					-
				</div>
				<div class="layui-input-inline">
					<input type="text" class="layui-input" id="sent-laydate-end" name="endDate" readonly placeholder="结束日期">
				</div>
			</div>

          <shiro:hasPermission name="LIST_INCOME_BILL">
	          <div class="layui-inline">
	            <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-incomeBill-search">
	              <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>查询
	            </button>
	            <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-reset">
	              <i class="layui-icon layui-icon-fonts-clear  layuiadmin-button-btn"></i>重置
	            </button>
	          </div>
          </shiro:hasPermission>
        </div>
      </div>
  	  <!-- 按钮区域  -->
      <div class="layui-card-body">
        <div style="padding-bottom: 10px;">
          <shiro:hasPermission name="EXPORT_INCOME_BILL">
          	<button class="layui-btn layuiadmin-btn-admin " data-type="export" onclick="exportList();">
          	 	<i class="layui-icon layui-icon-export layuiadmin-button-btn"></i>导出
          	</button>
          </shiro:hasPermission>
        </div>
        <!-- 数据表单 -->
        <table id="LAY-incomeBill-manage" lay-filter="LAY-incomeBill-manage"></table>
        
      </div>
    </div>
  </div>
  <script>
  	var typeJSON = <infopub:dicJson groupNo="A00010064" />;
  	var modeJSON = <infopub:dicJson groupNo="A00010063" />;
  	layui.config({
    	base: '${ctx}/resources/layuiadmin/' //静态资源所在路径
  	}).extend({
    	index: 'lib/index' //主入口模块
  	}).use(['index', 'table', 'set', 'laydate'], function(){
    	var $ = layui.$
    	,form = layui.form
    	,table = layui.table
    	,laydate = layui.laydate;
    	
  	    //开始日期
  	    var insStart = laydate.render({
  	      elem: '#sent-laydate-start'
  	      ,done: function(value, date){
  	        //更新结束日期的最小日期
  	        insEnd.config.min = lay.extend({}, date, {
  	          month: date.month - 1
  	        });
  	        
  	        //自动弹出结束日期的选择器
  	       insEnd.config.elem[0].focus();
  	      }
  	    });
  	    
  	    //结束日期
  	    var insEnd = laydate.render({
  	      elem: '#sent-laydate-end'
  	      ,done: function(value, date){
  	        //更新开始日期的最大日期
  	        insStart.config.max = lay.extend({}, date, {
  	          month: date.month - 1
  	        });
  	      }
  	    });
  	    
  	    //收款开始日期
  	    var incomeStart = laydate.render({
  	      elem: '#sent-laydate-incomeStart'
  	      ,done: function(value, date){
  	        //更新结束日期的最小日期
  	        incomeEnd.config.min = lay.extend({}, date, {
  	          month: date.month - 1
  	        });
  	        
  	        //自动弹出结束日期的选择器
  	       incomeEnd.config.elem[0].focus();
  	      }
  	    });
  	    
  	    //收款结束日期
  	    var incomeEnd = laydate.render({
  	      elem: '#sent-laydate-incomeEnd'
  	      ,done: function(value, date){
  	        //更新开始日期的最大日期
  	        incomeStart.config.max = lay.extend({}, date, {
  	          month: date.month - 1
  	        });
  	      }
  	    });
 		// 正则校验
    	form.verify({
    		//验证汉字
    	    CHS: [
    	    	/^[\u0391-\uFFE5]+$/
    	    	,'只能输入汉字'
    	  	],
	    	//大于0的正整数
		  	intNumber:[
				/^[1-9]\d*$/
				,'请输入正确的数字'
		  	]
		});

    	// 表单
    	table.render({
      		elem: '#LAY-incomeBill-manage'
      		,url: basePath + '/incomeBill/queryDataByCondition' //请求数据接口
      		,cols: [[
        		{type: 'checkbox', fixed: 'left'}
        		,{field: 'proCode', title: '项目ID', width:170}
        		,{field: 'proName', title: '收款归属项目', width:140}
        		,{field: 'incomeType', title: '收款类型', width:280}
				,{field: 'addTime', title: '创建时间', width:170, templet: function(d){
						return layui.util.toDateString(d.addTime,"yyyy-MM-dd HH:mm:ss");
					}
				},{field: 'actIncomeAmount', title: '应收金额', width:160, templet: function(d){
	  	      		  return formatCurrency(d.actIncomeAmount);
  	        	}},
				{field: 'actualIncomeAmt', title: '实收金额', width:160, templet: function(d){
						return formatCurrency(d.actualIncomeAmt);
					}},
				,{field: 'settlementMode', title: '结算方式', width:140},
				{field: 'status', title: '状态', width:110, fixed: 'right', templet: function (d) {
	        			if(d.status == '0'){
	          				return "待确认";
	          			}else if(d.status == '1'){
							return "确认收款";
						}else{
	        				return '';
						}
		        	}
 		    	}
        		,{title: '操作', width: 150, align:'center', fixed: 'right', templet: function(d){
      	  				var optStr ="";
      	  				<shiro:hasPermission name="VIEW_INCOME_BILL">
      	  					optStr += '<a class="layui-btn layui-btn-xs" lay-event="view"><i class="layui-icon layui-icon-form"></i>查看</a>';
  	  	  				</shiro:hasPermission>
      	  				<shiro:hasPermission name="UPDATE_INCOME_BILL">
      	 					//optStr += '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>';
  	  	  				</shiro:hasPermission>
  	  	  				<shiro:hasPermission name="CANCEL_INCOME_BILL">
		  	  	  			if(d.state == 1){//状态为已登记
      	 						optStr += '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="freeze"><i class="layui-icon layui-icon-pause"></i>作废</a>';
		   	        		}
						</shiro:hasPermission>
			  		  	return optStr;
        			}
        		}
      			]]
      		,page: true
      		,limit: 10
    	});
    
    	<shiro:hasPermission name="LIST_INCOME_BILL">
	    	//监听搜索
	    	form.on('submit(LAY-incomeBill-search)', function(data){
		      	//执行重载
		      	table.reload('LAY-incomeBill-manage', {page: {curr: 1},
		        	where: trimData(data)
		      	});
	    	});
	    	//重置清空
		    form.on('submit(LAY-user-back-reset)', function(data){
		    	reset_form('query-form');
		    	//额外处理select
				$("#query-form-settle").val('');
				$("#query-form-type").val('');
				$("#query-form-state").val('');
				if('${bindOrgId}'==null||'${bindOrgId}'==""){
					$("#query-select-orgId").val('${superOrgId}');
				}else{
					$("#query-select-orgId").val('${bindOrgId}');
				}
				form.render();
		    });
    	</shiro:hasPermission>
    
    	// 监听操作列
    	table.on('tool(LAY-incomeBill-manage)', function(obj){
      		var data = obj.data;
      		if(obj.event === 'freeze'){
          		layer.confirm('确定作废？',{icon:3, title :'提示'}, function(index){
          			$.ajax({
  						type : 'post',
  						url : basePath + '/incomeBill/updateStatus?id=' + data.id,
  						success:function(result){
  							if(result.success){
  								table.reload('LAY-incomeBill-manage'); //数据刷新
  								layer.close(index);
  							}else{
  								layer.msg(result.msg,{icon: 7});
  				  			}
  						}
  					});
          		});
      		}else if(obj.event === 'view'){
      			parent.layui.index.openTabsPage(basePath + '/incomeBill/toDealOrDetail?id='+data.id+'&proCode='+data.proCode,'收款登记 > 详情');
      		}
    	});
    	
    // 按钮事件
    var active = {
      add: function(){
    	  parent.layui.index.openTabsPage(basePath + '/incomeBill/add','收款单登记表 > 新建');
      }
    }  
    // data-type事件
    $('.layui-btn.layuiadmin-btn-admin').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
    
  });
  	
  	//导出excel
   	function exportList() {
   		layer.msg("暂未上线，敬请期待~",{icon: 1});
	}
  </script>
</body>
</html>

